const { exec } = require('child_process')
const path =require('path')
const axios = require('axios')

const {client,server} = require('../../config.json')


function startClient(originLog){
    // return 
    const UIURL = `http://localhost:${client.port}?port=${server.port}`

    axios({ method:'GET', url: UIURL
    }).then(res=>{
        originLog('🔵 node-conosle => UI界面已开启',res)
    }).catch(e=>{
        originLog('🔵 node-conosle => UI界面未开启',e.message)
        originLog(`🔵 node-conosle => 正在开启UI界面,浏览器打开 ${UIURL} 进行调试`)
        const clientPath = path.resolve(__dirname, '../client/')
        const cmd = `cd ${clientPath} && npx http-server --cors -p${client.port}`
        exec(cmd, (err, stdout, stderr) => {
            if(err){
                originLog(`🔵 node-conosle => 开启前端界面错误:${err}`)
            }
        })
    })
}


module.exports = startClient

